import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小梅就是酱子
 * Date: 2022-02-04
 * Time: 16:23
 */
public class 冒泡排序 {
    public static void main(String[] args) {
        int[] array={1,7,9,4,2,6};
        bubble(array);
        System.out.println(Arrays.toString(array));
    }
    public static void bubble(int[] array){
        for(int i=0;i<array.length-1;i++){
            boolean flg=false;
            for(int j=0;j<array.length-1-i;j++){
                if(array[j]>array[j+1]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                    flg=true;
                }
            }
            if(flg==false){
                return;
            }
        }
    }
}
